#pragma once

#include <glm/glm.hpp>
#include <memory>
#include <string>
#include <unordered_map>
#include <SDL2/SDL_mixer.h>
namespace engine
{
    namespace resource
    {
        class AudioManager
        {
            friend class ResourceManager;
        public: 
            struct SDLMixChunkDeleter
            {
                void operator()(Mix_Chunk* chunk) const noexcept;
            };

            struct SDLMixMusicDeleter
            {
                void operator()(Mix_Music* music) const noexcept;
			};

            AudioManager();
            ~AudioManager();

            AudioManager(const AudioManager&) = delete;
			AudioManager& operator=(const AudioManager&) = delete;
			AudioManager(AudioManager&&) = delete;
			AudioManager& operator=(AudioManager&&) = delete;

        private:
			std::unordered_map<std::string, std::unique_ptr<Mix_Chunk, SDLMixChunkDeleter>> m_sounds; //音频资源
			std::unordered_map<std::string, std::unique_ptr<Mix_Music, SDLMixMusicDeleter>> m_musics; //音乐资源

			Mix_Chunk* loadSound(const std::string& filePath); //加载音频
			Mix_Chunk* getSound(const std::string& filePath);  //获取音频
			void unloadSound(const std::string& filePath);     //卸载音频 
			void clearSounds();                                //清除所有音频资源                  

			Mix_Music* loadMusic(const std::string& filePath); //加载音乐
			Mix_Music* getMusic(const std::string& filePath);   //获取音乐
			void unloadMusic(const std::string& filePath);         //卸载音乐
			void clearMusics();                               //清除所有音乐资源                                  
        };
    }
}
